import { getList, setList, delLists, updateLists } from "@/api/classify"

let state = {
  list: [],
}

let mutations = {
  SET_LIST(state, arr) {
    state.list = arr
  }
}

let actions = {
  async getClassifyList({ commit }) {
    let { data } = await getList()
    let r = [{}].concat(data)
    commit("SET_LIST", r)
  },
  async sendList({ dispatch }, data) {
    await setList(data)
    dispatch("getClassifyList")
  },
  async updateList({ dispatch }, data) {
    await updateLists(data)
    dispatch("getClassifyList")
  },
  async deleteLists({ dispatch }, id) {
    await delLists(id)
    dispatch("getClassifyList")
  }
}

let getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}